#ifndef __SOC_TIMER_H__
#define __SOC_TIMER_H__

#include <functional>
#include <stdint.h>
#include "iperipheral.h"
#include "soc/soc_comm_def.h"
#include "interface/if_soc_timer.h"

#ifdef HAL_TIM_MODULE_ENABLED 

/// @brief 定时器
class SOC_Timer : public IF_SOC_Timer
{
public:
   explicit SOC_Timer(TimerDevId id = TimerDevId::None, void *handle = nullptr);
   virtual ~SOC_Timer();

public:
   //timer base 
   void SetPerscaler(int div);
   int GetPerscaler();
   void SetPeriod(int val);
   int GetPeriod();
   void SetTimerCount(uint32_t val);
   uint32_t GetTimerCount();

   void StartBase();
   void StopBase();
   void StartBase_IT();
   void StopBase_IT();

   void SetElapsedCallBack(IF_SOC_Timer::ElapsedCallBack cb);
   void RaiseElapsed_IRQ();

   //pwm
   void StartPwm(int ch);
   //驱动互补pwm
   void StartPwmPN(int ch);
   void StopPwm(int ch);
   /// @brief 
   /// @param ch 
   /// @param duty [0-100]
   void SetPwmDuty(int ch, float duty);
   /// @brief 
   /// @param ch 
   /// @param percent [0-1] 
   void SetPwmDutyP(int ch, float percent);
   void SetCompare(int ch, int val);
   int GetCompare(int ch);

   //oc 模式
   void StartOc_IT(int ch);
   void StopOc_IT(int ch);
   void SetNextPoint(int ch, int us);

   void SetOcCallBack(IF_SOC_Timer::OCCallBack cb);
   void RaiseOc_IRQ(int ch);

private:
   IF_SOC_Timer::ElapsedCallBack m_elapsedFunc = nullptr;
   IF_SOC_Timer::OCCallBack m_IRQOcFunc = nullptr;
};

#endif 

#endif // __SOC_TIMER_H__
